package com.example.reflection.config.util;

import com.example.reflection.service.RoleService;
import com.example.reflection.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;
import java.util.Arrays;

public class Request {
    /**
     * 反射
     * @param clazz
     * @param method
     * @throws Exception
     */
    public void sendReflection(Class clazz, Method method) throws Exception {
        // 模拟等待响应
        Thread.sleep(3000);
        System.out.println("[Request]:收到响应");
        method.invoke(clazz.newInstance());
    }

    /**
     * 接口调用
     * @param userService
     * @throws Exception
     */
    public void sendInterface(UserService userService) throws Exception {
        // 模拟等待响应
        Thread.sleep(3000);
        System.out.println("[Request]:收到响应");
        userService.findAll();
    }

    /**
     * lambda 表达式
     * @param roleService
     * @throws Exception
     */
    public void sendRole(RoleService roleService) throws Exception {
        Thread.sleep(3000);
        System.out.println("[Request]:收到响应");
        roleService.findRole();
    }

}
